package com.theme.passport.service.theme.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.theme.common.mvc.utils.PageUtils;
import com.theme.common.mvc.utils.Query;
import com.theme.passport.dao.theme.WidgeClassifyDao;
import com.theme.passport.entity.theme.ThemeClassifyEntity;
import com.theme.passport.entity.theme.WidgeClassifyEntity;
import com.theme.passport.service.theme.WidgeClassifyService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("widgeClassifyService")
public class WidgeClassifyServiceImpl extends ServiceImpl<WidgeClassifyDao, WidgeClassifyEntity> implements WidgeClassifyService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String keyword = (String) params.get("key");
        String parentId = (String) params.get("parentId");
        String isParent = (String) params.get("isParent");
        IPage<WidgeClassifyEntity> page = this.page(
                new Query<WidgeClassifyEntity>().getPage(params),
                new QueryWrapper<WidgeClassifyEntity>()
                        .like(StringUtils.isNotBlank(keyword), "name", keyword)
                        .eq(StringUtils.isNotBlank(parentId), "parent_id", parentId)
                        .eq(StringUtils.isNotBlank(isParent), "is_parent", isParent)
                        .orderByAsc("sort_order")
        );
        return new PageUtils(page);
    }

}